package com.sh4.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.sh4.entity.User;

public class ContextHeader {

	/***
	 * 获取当前登录对象
	 * @return
	 */
	public static User getUser() {
		
		User user = (User) getSession().getAttribute("userCode");
		return user;
	}
	
	/**
	 * 获取 HttpServletRequest
	 * @return
	 */
	public static HttpServletRequest getRequest(){  
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();  
        return requestAttributes==null? null : requestAttributes.getRequest();  
    }  
	
	/***
	 * 获取当前客户端session
	 * @return
	 */
	public static HttpSession getSession() {
		
		return getRequest().getSession();
	}
	
	/***
	 * 获取当前登录人code
	 * @return
	 */
	public static String getUserCode() {
		
		return getUser().getUserCode();
	}
	
	
}
